home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
ae_14.zip
/
AE1.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-03-08
|
22KB
|
611 lines
unit AE1 ;
{$B-}
{$I-}
{$S+}
{$V-}
{-----------------------------------------------------------------------------}
{ This unit contains all basic procedures }
{-----------------------------------------------------------------------------}
interface
uses Crt,Dos,AE0 ;
function UpperCase (S:string) : string ;
function WordToString (Num:word ; Len:integer) : string ;
function Wildcarded (Name : PathStr) : boolean ;
function Exists (FileName : PathStr) : boolean ;
procedure MoveToScreen (var Source,Dest ; Len : word) ;
procedure MoveFromScreen (var Source,Dest ; Len : word) ;
procedure SaveArea (X1,Y1,X2,Y2:word ; var MemPtr:ScreenBlockPtr) ;
procedure RestoreArea (X1,Y1,X2,Y2:word ; var MemPtr:ScreenBlockPtr) ;
function Grow (Index:word ; Chars:word) : boolean ;
procedure Shrink (Index:word ; Chars:word) ;
function GetCursor : byte ;
procedure SetCursor (Cursor : byte) ;
procedure CursorTo (X,Y : byte) ;
procedure WarningBeep ;
function ReadKeyNr : word ;
procedure SetBottomLine (LineText:string) ;
procedure Message (Contents:string) ;
procedure ErrorMessage (ErrorNr:byte) ;
procedure Pause ;
procedure CheckDiskError ;
procedure PutFrame (X1,Y1,X2,Y2 : byte ; Border : string) ;
procedure ClearArea (X1,Y1,X2,Y2 : byte) ;
procedure ClearWorkspace (Wsnr:byte) ;
procedure ClearKeyBuffer ;
implementation
{-----------------------------------------------------------------------------}
{ Converts all lower case letters in a string to upper case. }
{-----------------------------------------------------------------------------}
function UpperCase (S : string) : string ;
var Counter : word ;
begin
for Counter := 1 to Length(S) do S[Counter] := UpCase (S[Counter]) ;
UpperCase := S ;
end ;
{-----------------------------------------------------------------------------}
{ Converts an expression of type word to a string }
{ if Len < 0 then string is adjusted to the left; string length is <Len> }
{ if Len > 0 then string is adjusted to the right; string length is <-Len> }
{ if Len = 0 then string is not adjusted; string has minimum length }
{-----------------------------------------------------------------------------}
function WordToString (Num:word ; Len:integer) : string ;
var S : string[5] ;
begin
if Len > 0
then Str (Num:Len,S)
else begin
Str (Num,S) ;
Len := - Len ;
if (Len > 0) and (Length(S) < Len)
then begin
FillChar (S[Length(S)+1],Len-Length(S),' ') ;
S[0] := Chr(Len) ;
end ;
end ;
WordToString := S ;
end ;
{-----------------------------------------------------------------------------}
{ Deletes all spaces on the left of a string. }
{-----------------------------------------------------------------------------}
function TrimLeft (S:string) : string ;
begin
while (Length(S) >0) and (S[1] = ' ') do Delete (S,1,1) ;
TrimLeft := S ;
end ;
{-----------------------------------------------------------------------------}
{ Indicates whether a filename contains wildcard characters }
{-----------------------------------------------------------------------------}
function Wildcarded (Name : PathStr) : boolean ;
begin
Wildcarded := (Pos('*',Name) <> 0) or (Pos('?',Name) <> 0) ;
end ;
{-----------------------------------------------------------------------------}
{ Returns True if the file <FileName> exists, False otherwise. }
{-----------------------------------------------------------------------------}
function Exists (FileName : PathStr) : boolean ;
var SR : SearchRec ;
begin
FindFirst (FileName,ReadOnly + Hidden + SysFile,SR) ;
Exists := (DosError = 0) and (not Wildcarded(Filename)) ;
end ;
{-----------------------------------------------------------------------------}
{ Moves <Len> bytes of memory to screen memory. }
{ From the TCALC spreadsheet program delivered with every copy of Turbo }
{ Pascal 5.5 }
{-----------------------------------------------------------------------------}
procedure MoveToScreen (var Source,Dest ; Len : word) ;
external ;
{-----------------------------------------------------------------------------}
{ Moves <Len> bytes of screen memory to memory. }
{ From the TCALC spreadsheet program delivered with every copy of Turbo }
{ Pascal 5.5 }
{-----------------------------------------------------------------------------}
procedure MoveFromScreen (var Source,Dest ; Len : word) ;
external ;
{$L TCMVSMEM.OBJ }
{-----------------------------------------------------------------------------}
{ Saves the contents of a rectangular part of the screen to memory. }
{ Upper left corner is (X1,Y1), lower right is (X2,Y2) }
{ Also claims the amount of memory needed. }
{-----------------------------------------------------------------------------}
procedure SaveArea (X1,Y1,X2,Y2:word ; var MemPtr:ScreenBlockPtr) ;
var LineLen : byte;
Index : word;
Counter : byte;
begin
LineLen := X2 - X1 + 1;
GetMem (MemPtr,LineLen*(Y2-Y1+1)*2) ;
Index := 1 ;
for Counter := Y1 to Y2 do
begin
MoveFromScreen (DisplayPtr^[Counter,X1],MemPtr^[Index],LineLen*2);
Inc (Index,LineLen)
end;
{$IFDEF DEVELOP }
if MemAvail < MinMemAvail
then MinMemAvail := MemAvail ;
{$ENDIF }
end;
{-----------------------------------------------------------------------------}
{ Reverse of SaveArea }
{-----------------------------------------------------------------------------}
procedure RestoreArea (X1,Y1,X2,Y2:word ; var MemPtr:ScreenBlockPtr) ;
var LineLen : byte;
Index : word;
Counter : byte;
begin
LineLen := X2 - X1 + 1;
Index := 1;
for Counter := Y1 to Y2 do
begin
MoveToScreen (MemPtr^[Index],DisplayPtr^[Counter,X1],LineLen*2);
Inc (Index,LineLen)
end;
FreeMem (MemPtr,LineLen*(Y2-Y1+1)*2) ;
end;
{-----------------------------------------------------------------------------}
{ Expands the text in the buffer of the current workspace at position }
{ <Index> by <Chars> characters. Function result is False if there is not }
{ enough space left, True otherwise. }
{ Index values of Mark and in position stack are adapted }
{-----------------------------------------------------------------------------}
function Grow (Index:word ; Chars:word) : boolean ;
var Counter : byte ;
begin
with Workspace[CurrentWsnr] do
if Chars > (WsBufSize - BufferSize)
then begin
{ not enough space }
ErrorMessage (1) ;
Grow := False ;
end
else begin
{ move rest of text forward }
Move (Buffer^[Index],Buffer^[Index+Chars],BufferSize-Index+1) ;
Inc (BufferSize,Chars) ;
{ adapt Mark and position stack }
if Mark >= Index then Inc (Mark,Chars) ;
for Counter := 1 to PosStackpointer do
begin
if PosStack[Counter] >= Index
then Inc (PosStack[Counter],Chars) ;
end ;
ChangesMade := True ;
Grow := True ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Deletes <Chars> characters from the buffer in the current workspace, }
{ starting on position <Index>. }
{ Index values of Mark and in position stack are adapted }
{-----------------------------------------------------------------------------}
p